package com.vueperson.vueperson.t1.CreationalPattern.PrototypePattern.PrototypeManager;



import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;

import java.io.*;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ConcretePrototypeB extends Prototype implements Serializable{
    private String name;

    @SneakyThrows
    @Override
    public ConcretePrototypeB clone()  {
        //将对象写入流中
        ByteArrayOutputStream bao=new ByteArrayOutputStream();
        ObjectOutputStream oos=new ObjectOutputStream(bao);
        oos.writeObject(this);
        //将对象从流中取出
        ByteArrayInputStream bis=new ByteArrayInputStream(bao.toByteArray());
        ObjectInputStream ois=new ObjectInputStream(bis);

        return (ConcretePrototypeB) ois.readObject();
    }
}
